package com.itheima.stock.config;


import org.springframework.amqp.core.*;
import org.springframework.amqp.support.converter.Jackson2JavaTypeMapper;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfig {
    /**
     * 消息转换器
     * @return
     */
    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }

    /**
     * 创建国内大盘消息队列
     * @return
     */
    @Bean
    public Queue innerMarketQueue() {
        return new Queue("innerMarketQueue",true);
    }

    /**
     * 定义股票信息交换机
     */
    @Bean
    public TopicExchange stockExchange() {
        return new TopicExchange("stockExchange",true,false);
    }

    /**
     * 绑定国内大盘消息队列
     * @return
     */
    @Bean
    public Binding innerMarketBinding() {
        return BindingBuilder.bind(innerMarketQueue()).to(stockExchange()).with("inner.market");
    }

}
